import React, { memo, useMemo, useState } from 'react'

function calcNumTotal(num) {
  console.log('执行计算');
  let total = 0
  for(let i = 1; i<= num; i++) {
    total += i
  }
  return total
}

const App = memo(() => {
  const [ count, setCount ] = useState(0)

  let result = useMemo(() => {
    return calcNumTotal(10)
  },[])
  return (
    <>
      <div>计算结果: { result }</div>
      <div>计数器：{ count }</div>
      <div><button onClick={ e=> setCount(count+1) }>+1</button></div>
    </>
  )
})

export default App


